/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.StockManage;

import GUI.MainFunction;
import connection.ManLabConnection;
import entities.StockDetail;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 *
 * @author Admin
 */
public class DeleteStock {

    private ManLabConnection cnn;
    private ArrayList<String> qry;
    private ArrayList<StockDetail> stockDetails;
    private StockDetail stockDetail;     
    private MainFunction parentFrame;

    public DeleteStock(ArrayList<StockDetail> stockDetails, StockDetail stockDetail, MainFunction parentFrame) {
        this.stockDetails = stockDetails;
        this.stockDetail = stockDetail;
        this.parentFrame = parentFrame;
        this.cnn = new ManLabConnection();
        this.qry = new ArrayList<String>();
    }        

    public void deleteStock() {
        int sID = stockDetail.getsID();        
boolean cn=        cnn.createConnection();
        String qry1 = "delete from ItemRequire where sID=" + sID + "";
        qry.add(qry1);
        String qry2 = "delete from StockDetail where sID=" + sID + "";
        qry.add(qry2);
        for (String s : qry) {
            cnn.executeQuery(s);
        }
        cnn.closeConnection();               
        stockDetails.remove(stockDetail);
        JOptionPane.showMessageDialog(parentFrame, "Deleted successfully!!!");
        this.parentFrame.refreshReportTableView();
    }
}
